package com.ghost.UI
{
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.control.CairngormEventDispatcher;
	import com.ghost.event.Skin_Event;
	import com.ghost.model.UI_skin_data;
	
	import fl.controls.Button;
	
	import flash.display.Bitmap;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.media.SoundTransform;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	
	public class Ghost_Btn extends Button
	{
		private var callback:Function;//按钮的回调函数
		private var style_v:Vector.<Object>;//样式数组
		private var style_str_v:Vector.<String>;//样式名数组
		/**
		 * @param call_back 回调函数点击
		 * @param bitmap_v 按钮的4个状态数据(类型class) 
		 * @param soundtransform 分配给此按钮的 SoundTransform 对象
		 */		
		public function Ghost_Btn(bitmap_v:Vector.<Object>=null,call_back:Function=null,soundtransform:SoundTransform = null)
		{
			//this.addEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			this.useHandCursor = true;
			this.label = "";
			this.setStyle('textFormat',new TextFormat(null,12,0xffffff));
			callback = call_back;
			if(bitmap_v != null)
			{
				style_v = new Vector.<Object>();
				style_v = bitmap_v;
				style_str_v = new <String>['disabledSkin','overSkin','downSkin','upSkin','icon'];
				register_style(style_v);
			}
			if(soundtransform != null)
			{
				//播放按钮声音
			}
			//trace(this.getStyle("disabledSkin"));
			if(call_back!=null)this.addEventListener(MouseEvent.CLICK,cHandler);//点击按钮
			CairngormEventDispatcher.getInstance().addEventListener(Skin_Event.skin_change_event,change_Handler);//所有btn更换
		}
		private function remove_Handler(e:Event):void
		{
			this.removeEventListener(Event.REMOVED_FROM_STAGE,remove_Handler);
			this.removeEventListener(MouseEvent.CLICK,cHandler);//点击按钮
			CairngormEventDispatcher.getInstance().removeEventListener(Skin_Event.skin_change_event,change_Handler);//所有btn更换
		}
		/**
		 * 设置样式
		 * @param v:样式数组
		 */		
		private function register_style(v:Vector.<Object>):void
		{
			var i:int = 0;
			for(i;i<4;i++)
			{
				this.setStyle(style_str_v[i],style_v[i]);
			}
			//this.setStyle("focusRectSkin",null)
		}
		/**
		 * 点击调用回调函数
		 */		
		private function cHandler(e:MouseEvent):void
		{
			callback(e);
		}
		public function set_icon(c:Object=null):void
		{
			if(c)this.setStyle(style_str_v[4],c);
			else this.setStyle(style_str_v[4],style_v[4]);
		}
		/**
		 * @param formate :label文本样式
		 */		
		public function set textformat(formate:TextFormat):void
		{
			this.setStyle('textFormat',formate);
			if(formate.size != null)
			{
				this.textField.height = Number(formate.size);
			}
		}
		/**
		 * @param w 设置宽
		 * @param h 设置高
		 */		
		public function setsize(w:Number,h:Number):void
		{
			this.setSize(w,h);
			this.textField.width = w;
			this.textField.height = h;
		}
		/**
		 * 移除更换皮肤事件
		 */
		public function remove_skin_event():void
		{
			CairngormEventDispatcher.getInstance().removeEventListener(Skin_Event.skin_change_event,change_Handler);//所有btn更换
		}
		/**
		 * 按钮更换样式 e.data可以是数字 代表第几套皮肤
		 */		
		private function change_Handler(e:Skin_Event):void
		{
			register_style(UI_skin_data.ghost_btn_skin_o[e.data]);
		}
		//test用 
		public function init(data:*,f:Function):void
		{
			
		}
	}
}